#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <cmocka.h>

#define common_namespace
#include <common/macro/enum.h>

static void
test_argument_macro (__attribute__((unused)) void **state)
{
  assert_int_equal (common_args_length (1, 2, 3, 3), 4);
  assert_int_equal (args_get_first (1, 2, 3, 4), 1);
  assert_int_equal (args_get_last (1, 2, 3, 4), 4);
}

static void
test_enum_macro (__attribute__((unused)) void **state)
{
  define_enum (colors, black, red, white);

  for_each_enum(color, colors)
  {
    assert_in_range(color, black, white);
  }

  assert_int_equal (black, 0);
  assert_int_equal (white, 2);
  assert_int_equal (colors_begin, black);
  assert_int_equal (colors_end, white + 1);
  assert_string_equal (colors_to_string (black), "black");
  assert_string_equal (colors_to_string (white), "white");
  assert_string_equal (colors_to_string (10), "undefined");
  assert_int_equal (args_length_compile (black, red, white), 3);
}

int
main (void)
{
  const struct CMUnitTest tests[] =
  {
    cmocka_unit_test (test_enum_macro),
    cmocka_unit_test (test_argument_macro),
  };

  return cmocka_run_group_tests (tests, NULL, NULL);
}
